import { Component, OnInit } from '@angular/core';
import { Router,Event,NavigationEnd,NavigationStart }  from '@angular/router';
import { GlobalVariable} from "../global.config";
import { LoginService } from '../service/login.service';
import { HideElementService } from "../service/hideElement.service";
import { TranslateService } from 'ng2-translate';

@Component({
  selector: 'app-page',
  templateUrl: './page.component.html',
  styleUrls: ['./page.component.css']
})
export class PageComponent implements OnInit {

  title = 'MONITOR';
  public app = GlobalVariable.app;
  private baseURL = GlobalVariable.BASE_API_URL;
  public menus = JSON.parse(JSON.stringify(GlobalVariable.menu));

  public asideFolded:boolean = GlobalVariable.app.settings.asideFolded;
  public drop = {lan: false,info:false,full:false}; 
 
  public account = {short_name:'',facing_img:'',username:''};

  constructor(
    private loginService:LoginService,
    private router: Router,
    public translate: TranslateService,
    private he:HideElementService) {
    this.menus.head = this.he.hideElement(this.menus.head);
  }


  ngOnInit(){
    //验证localStorage
    if(!(localStorage.getItem("isLogin"))) {
      this.router.navigateByUrl('/login');
    }
    else{
      this.account = JSON.parse(localStorage.getItem("account"));
      
    }
    
  }

  logout():void{
    this.loginService.logout();
  }


  selectMenu(type:number,idx:any):void{

    for(let i in this.menus.children){
      if(idx != i) this.menus.children[i].active = false;
    }
    if(type != 1)  this.menus.children[idx].active = !this.menus.children[idx].active;

  }

 }



